package org.amphiprion.diceroller;

import java.io.File;
import java.util.ArrayList;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends Activity {
	// private LauncherScreen launcherScreen;
	//
	// public MainActivity() {
	// super(768, 1280);
	//
	// }

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// launcherScreen = new LauncherScreen(this);
		// view.addScreen(launcherScreen);
		setContentView(R.layout.activity_main);
		clickButton(null);
	}

	public void clickButton(View view) {
		final ArrayList<String> files = new ArrayList<String>();
		ArrayList<String> gameNames = new ArrayList<String>();
		String[] dirs = new File(ApplicationConstants.ROOT_DIRECTORY + "/games").list();
		for (int i = 0; i < dirs.length; i++) {
			File f = new File(ApplicationConstants.ROOT_DIRECTORY + "/games/" + dirs[i] + "/game-definition.xml");
			if (f.exists()) {
				gameNames.add(dirs[i]);
				files.add(ApplicationConstants.ROOT_DIRECTORY + "/games/" + dirs[i]);
			}
		}
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		String[] titles = new String[files.size()];
		titles = gameNames.toArray(titles);
		builder.setTitle(R.string.choose_game).setItems(titles, new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				Intent intent = new Intent(MainActivity.this, LauncherActivity.class);
				intent.putExtra("GAME_DIR", files.get(which));
				startActivity(intent);
			}
		});
		builder.show();
	}

	// @Override
	// protected void onActivityResult(int requestCode, int resultCode, Intent data) {
	// openOptionsMenu();
	// }
}
